/**
 *数据防抖
 * @param {T} value
 * @param {*} delay
 * @return {*}
 */

import {useState, useEffect} from 'react'

function useDebounceValue(value: any, delay: number) {
  const [debounceVal, setDebounceVal] = useState('')

  useEffect(() => {
    let handler = setTimeout(() => {
      setDebounceVal(value)
    }, delay)

    return () => {
      clearTimeout(handler)
    }
  }, [value, delay])

  return debounceVal
}

export default useDebounceValue
